#pragma once

class CWinApp;
class CWindow
{
protected:
	int m_nPositionX, m_nPositionY;
	int m_nWidth, m_nHeight;
	DWORD m_dwStyle;
	HWND m_hWnd;
	tstring m_strCWindowTitle;
	CWinApp* m_pApp;

private:
	typedef std::map<HWND, CWindow*>::iterator WindowMapIter;
	static std::map<HWND, CWindow*> _windowMap;
	static CWindow* _pOnCreateWindow;

public:
	CWindow(void);
	~CWindow(void);

	bool Create(CWinApp* app, tstring& strCWindowTitle, HMENU hMenu = NULL, CWindow* pParentWin = NULL);
	void Show(BOOL bShow);

protected:
	void DeleteWindow(HWND hWnd);

	bool RegistWindowClass(LPCTSTR className, UINT classStyle, HCURSOR hCursor = NULL,
		HBRUSH hbrBackground=(HBRUSH)(COLOR_WINDOW+1), HICON hIcon = NULL);

	virtual LRESULT WndMsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
	virtual bool PreCreate(CREATESTRUCT& cs);
	virtual bool OnCreate(CREATESTRUCT* cs);
	virtual void OnPaint();
	virtual void OnDestroy();
	virtual void OnCommand();
public:
	virtual bool OnIdle(ULONG ulCount);

private:
	static LRESULT CALLBACK _WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
};
